<?php
namespace App\Http\Models;



class Fang extends Base
{
    public function owner(){
        return $this->belongsTo(FangOwner::class,'fang_owner');
    }


    //添加和修改 关联数据
    public function relationData(){
        //业主
        $ownerData = FangOwner::get();
        //省份数据
        $cityData = City::where('pid',0)->get();
        //租期方式
        $fang_rent_type_id = Fangattr::where('field_name','fang_rent_type')->value('id');
        $fang_rent_type_data = Fangattr::where('pid',$fang_rent_type_id)->get();
        //朝向
        $fang_direction_id  = Fangattr::where('field_name','fang_direction')->value('id');
        $fang_direction_data = Fangattr::where('pid',$fang_direction_id)->get();
        //租赁方式
        $fang_rent_class_id = Fangattr::where('field_name','fang_rent_class')->value('id');
        $fanga_rent_class_data = Fangattr::where('pid', $fang_rent_class_id)->get();
        //配套方式
        $fang_config_id = Fangattr::where('field_name','fang_config')->value('id');
        $fang_config_data = Fangattr::where('pid',$fang_config_id)->get();
        //返回数据
        return [
            'ownerData' => $ownerData,
            'cityData' => $cityData,
            'fang_rent_type_data'=> $fang_rent_type_data,
            'fang_direction_data' => $fang_direction_data,
            'fang_rent_class_data' => $fanga_rent_class_data,
            'fang_config_data' => $fang_config_data
        ];
    }
}
